Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes and new warning for Neurons classes. #101

Merged
merged 1 commit into from
Feb 1, 2024

Conversation

colleenjg
Copy link
Contributor

@colleenjg colleenjg commented Feb 1, 2024

Small fixes and new warning for Neurons classes.

Fixes:

  • Added an error in VectorCells init if class is initialized directly.
  • Removed default value of None for Other_Agent in AgentVectorCells init, as None is not an allowed value.
  • Raised an error in ObjectVectorCells if there are no objects in the environment.

New warning added:

  • Added a warning in classes where the number of neurons can be changed internally, overriding params["n"]. This is to avoid confusion when a user requests 10 neurons, but ends up with 64, for example. The added code specifically checks whether n was passed as a parameter, and will not produce a warning if n was added in from a default parameter dictionary.

New warning examples:

  1. In the simple case that applies to HeadDirectionCells in 1D environments and to SpeedCell, if you run something like:
from ratinabox import Agent, Environment, SpeedCell

Env = Environment(params={"objects": [[0.5, 0.5]]})
Ag = Agent(Env)
SpeedCell(Ag, params={"n": 3})

you get:

UserWarning: Ignoring 'n' parameter value (3) that was passed for SpeedCell. Only 1 speed cell is needed.

  1. In the slightly more complex case that applies to VectorCells and its child classes, if you run something like
from ratinabox import Agent, Environment, FieldOfViewOVCs

Env = Environment(params={"objects": [[0.5, 0.5]]})
Ag = Agent(Env)

FieldOfViewOVCs(Ag, params={"object_tuning_type": "random", "cell_arrangement": "diverging_manifold"})
FieldOfViewOVCs(Ag, params={"object_tuning_type": "random", "cell_arrangement": "random", "n":10})

then there's no warning. In the first case, because you didn't specify an n value [1] and in the second case, because the n value is not changed.

However, if you run

from ratinabox import Agent, Environment, FieldOfViewOVCs

Env = Environment(params={"objects": [[0.5, 0.5]]})
Ag = Agent(Env)
FieldOfViewOVCs(Ag, params={"object_tuning_type": "random", "cell_arrangement": "diverging_manifold", "n": 10})

you get:

UserWarning: Ignoring 'n' parameter value (10) that was passed, and setting number of ObjectVectorCell neurons to 58, inferred from the cell arrangement parameter.

[1] To ensure that no superfluous warning is produced in this case, I had to create an extra attribute _warn_n_change that can be set in a child class. This allows the init of VectorCells to know whether n was actively passed by the user or was added to params at some point during the initialization chain (e.g., from a child class' default parameters).

…ation of a neuron layer.

Adde an error in VectorCells init if class is initialized directly.
Removed default value of None for `Other_Agent` in AgentVectorCells init, as None is not an allowed value.
Raised an error in ObjectVectorCells if there are not objects in the environment.
Copy link
Collaborator

@TomGeorge1234 TomGeorge1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in person these look great...and I'm happy with your solution to the awkward issue of the n parameter for vector cells, we can always refine it down the line but its only a tiny warning for good housekeeping after all

@TomGeorge1234
Copy link
Collaborator

Enormous thanks, as per, for your work on this!

@TomGeorge1234 TomGeorge1234 merged commit 259d072 into RatInABox-Lab:main Feb 1, 2024
3 checks passed
colleenjg added a commit to colleenjg/RatInABox that referenced this pull request Feb 2, 2024
…atInABox-Lab#102.

Reintroduced an equality check for raising a warning if value of self.n was passed, but is reset internally in a VectorCells class.
Equality is checked if `cell_arrangement` does not end in `"manifold"` (i.e., `"diverging_manifold"` or `"uniform_manifold"`.
If `cell_arrangement` is `"random"` or a callable function, a warning is only raised if the value of self.n would actually change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants